﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using MKAdminCore.Controllers;
using MKAdminCore.DTO.CusAttribute;
using MKAdminCore.DTO.Web.Common;
using MKAdminCore.DTO.Web.File;
using MKAdminCore.ToolKit.Config;
using MKAdminCore.ToolKit.Extensions;
using MKAdminCore.ToolKit.PosterImgHelper;

namespace MKAdminCore.Areas.File.Controllers
{
    [Area("File")]
    [Route("File/[controller]/[action]")]
    public class PosterCompoundController : BaseMvcController
    {
        public IActionResult Index()
        {
            return View(PageViewFilesConfig.PosterCompoundIndex);
        }

        /// <summary>
        /// 生成海报图
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> CreatePosterImg(PosterCompoundParam param)
        {
            var result = new HttpResponseResult<PosterCompoundModel>() { Msg = "" };
            var validateResult = param.Validate();
            if (validateResult.Code != 200)
            {
                result.Msg = validateResult.Msg;
                result.Code = validateResult.Code;
                return Ok(result);
            }

            result = await PosterImgHelper.CreatePosteImage(param.Title, param.PosterCoverUrl, param.OriginPrice, param.FinalPrice);

            return Ok(result);
        }
    }
}